package ClasesExtras;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

public class ValidacionOperarios {

	public String valOperario(String ced, String pass) {
		HttpClient httpClient = new DefaultHttpClient();
		HttpPost post = new HttpPost("http://10.1.1.174:3000/validar");// operarios
		post.setHeader("content-type", "application/json");

		try {

			// Construimos el objeto en formato JSON
			JSONObject dato = new JSONObject();
			dato.put("cedula", ced);// cedula del operario
			dato.put("password", pass);// contraseña del operario

			StringEntity entity = new StringEntity(dato.toString());
			post.setEntity(entity);
			HttpResponse resp = httpClient.execute(post);
			String respStr = EntityUtils.toString(resp.getEntity());

			return respStr;

		} catch (Exception ex) {
			String respStr = "malo";
			return respStr;

		}

	}

	public boolean valCalidad(String ced, String pass) {
		HttpClient httpClient = new DefaultHttpClient();
		HttpPost post = new HttpPost("http://10.1.1.174:3000/");// empleado
																// calidad
		post.setHeader("content-type", "application/json");
		boolean cal;
		try {

			// Construimos el objeto en formato JSON
			JSONObject dato = new JSONObject();
			dato.put("", ced);// cedula de calidad
			dato.put("", pass);// contraseña de calidad

			StringEntity entity = new StringEntity(dato.toString());
			post.setEntity(entity);
			HttpResponse resp = httpClient.execute(post);
			String respStr = EntityUtils.toString(resp.getEntity());

			if (respStr.equals("true")) {

			}
			cal = true;
		} catch (Exception ex) {

			cal = false;
		}
		return (cal);
	}

	public boolean valAdmin(String ced, String pass) {
		HttpClient httpClient = new DefaultHttpClient();
		HttpPost post = new HttpPost("http://10.1.1.174:3000/");// empleado
																// administrador
		post.setHeader("content-type", "application/json");
		boolean adm;
		try {

			// Construimos el objeto en formato JSON
			JSONObject dato = new JSONObject();
			dato.put("", ced);// cedula del admin
			dato.put("", pass);// contraseña del admin

			StringEntity entity = new StringEntity(dato.toString());
			post.setEntity(entity);
			HttpResponse resp = httpClient.execute(post);
			String respStr = EntityUtils.toString(resp.getEntity());

			if (respStr.equals("true")) {

			}
			adm = true;
		} catch (Exception ex) {

			adm = false;
		}
		return (adm);
	}
}
